// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import ElementUI from 'element-ui';
import 'reset-css';
import 'element-ui/lib/theme-chalk/index.css';
import App from './App'
import router from './router'
import store from './store'
import 'bootstrap/dist/css/bootstrap.min.css'
import 'bootstrap/dist/js/bootstrap.min.js'
import { sync } from 'vuex-router-sync'
sync(store, router);

Vue.use(ElementUI);
Vue.config.productionTip = false
Vue.prototype.URL_HOST = process.env.URL_HOST;
/**
 * 路由拦截
 */
router.beforeEach((to, from, next) => {
    /**
     * 判断前往的路由是否需要身份验证
     */
    if (to.matched.some(record => record.meta.requiresAuth)) {
        const access_token = store.state.account.access_token;
        //通过access_token判断用户是否已经登录
        if (!access_token) {
            next({
                path: '/login'
            })
        } else {
            next()
        }
    } else {
        next()
    }
});
/* eslint-disable no-new */
new Vue({
  store,
  router,
  render: h => h(App)
}).$mount('#app');
